using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq;
using System.Linq;
using CSW.Framework.UI.Binding;
using CSW.Framework.UI.DevEx.Binding;
using CSW.Framework.UI.DevEx.Forms;

namespace CSW.Security.UI.DevEx.Forms
{
	/// <summary>
	/// SecurityRoleEditForm
	/// </summary>
	public partial class SecurityUserEditForm : DXBaseEditForm
	{
		private readonly EditFormBinder m_Binder;
		private readonly Security_User m_Security_User;

		/// <summary>
		/// Initializes a new instance of the <see cref="SecurityUserEditForm"/> class.
		/// </summary>
		public SecurityUserEditForm(Security_User security_User)
		{
			InitializeComponent();

			m_Security_User = security_User;

            m_Binder = new EditFormBinder(this, m_Security_User, dxError, btnSave, "User", RecordType.Parent, ShowErrors.AfterSave);
			m_Binder.Bind(new BindableTextEdit(txtUserID), "UserID");
			m_Binder.Bind(new BindableTextEdit(txtFirstName), "FirstName");
			m_Binder.Bind(new BindableTextEdit(txtLastName), "LastName");
			m_Binder.Bind(new BindableCheckEdit(chkIsAppSupport), "IsAppSupport");
			m_Binder.UpdateControls();

			roleSelectUserControl.Setup<Security_Role, Security_UserRole>(
				Security_Role.GetAll(),
				m_Security_User.Security_UserRole,
				p => p.Security_Role,
				(q, r) => q.RoleID == r.RoleID,
				s => new Security_UserRole { Security_Role = s },
				SecurityTest.DataContextInstance.Security_UserRole,
				new[] { "ID", "Description" },
				new[] { "RoleID", "Description" },
				false,
				m_Binder
			);
		}
	}
}